<template>
	<view class="usersearch">
		
		<u-navbar title=""  :border-bottom="false"  >
			<view class="navbar__search">
					<u-icon name="search" color="#000000" :size="28"></u-icon>
					<u-input v-model="phone" placeholder="搜索园区" class="navbar__search__text" :focus="true" @input="checkInput"/>
			</view>
			<view class="navbar__submit" :slot="right" @click="search">搜索</view>
		</u-navbar>
		<view v-if="phone!=''">

			<view v-if="searchStatus=='loadding'" class="usersearch__loadding">
				<u-loading mode="circle" ></u-loading>
			</view >
			<view v-else-if="searchStatus=='finish'" class="usersearch__result">
				<view  class="usersearch__result__title"  >
					搜素结果
				</view>
				<view class="usersearch__result__user__empty" v-if="searchUser==null">
					<u-empty :text="searchMsg" mode="search"></u-empty>
				</view>
				
				<view v-else class="usersearch__result__user"  >

					<view class="usersearch__result__user__pic">
						<u-avatar :src="searchUser.avatarUrl" size="100" style="margin-right: 10px;"></u-avatar>
					</view>
					<view class="usersearch__result__user__text">
						<view class="usersearch__result__user__text__username">{{searchUser.nickname}}</view>
						<view class="usersearch__result__user__text__description">{{searchUser.realName}}</view>
					</view>
					<view class="usersearch__result__user__set">
						<view class="usersearch__result__user__set__edit" @click="toSetAuthority(searchUser)">
							<u-icon name="plus" ></u-icon>
								设置权限
						</view>
					</view>

<!-- 					<u-modal v-model="setModalshow" :title="'添加员工'+searchUser.realName" :mask-close-able="true">
						<u-radio-group  class="usersearch__result__user__set__modal" v-model="searchUser.authority">
							<u-radio 
								class="usersearch__result__user__set__modal__item"
								v-for="(item, index) in authorList" :key="index" 
								:name="item.name"
							>
								{{item.name}}
							</u-radio>
						</u-radio-group>
					</u-modal> -->
				</view>
			</view>
			<view v-else>
				
			</view>
		</view>
		<view v-else>
			
		</view>
	</view>
</template>

<script>
	import authorityData from "./authorityData.js"
	export default {
		data() {
			return {
				searchResult:authorityData.searchResultList,
				searchUser:null,
				searchStatus:"",
				searchMsg:"",
				phone:'',
				setModalshow:false,
				authorList:[
					{
						name:"员工管理员",
					},{
						name:"公司一级管理员",
					},{
						name:"公司二级管理员",
					},{
						name:"普通员工",
					},{
						name:"普通用户",
					}
				],
				searched:false
			}
		},
		methods: {
			checkInput(){
					if(this.phone=="")
					{
						this.searchStatus="inputing"
					}
			},
			goback(){
				uni.navigateBack()
			},
			search(){
				if(this.phone==""){
					uni.showToast({
						title:"请输出手机号",
						icon:"none",
						duration:2000
					})
				}
				this.searchStatus="loadding"
				let searchData={
					phone:this.phone
				}
				this.$Axios({
					url:this.$store.state.baseURL+"/user/searchbyphone",
					method:"get",
					params:searchData
				}).then(response=>{
					this.searchStatus="finish"
					if(response.data.state=="Success"){
						if(response.data.msg=="user is not exist"){
							this.searchUser=null
							this.searchMsg="此用户不存在"
						}else{
							this.searchUser=response.data.msg
						}
						
						
					}else{
						this.searchMsg=response.data.msg
					}
					
				})
				
			},
			toSetAuthority(user){
				this.$Router.push({ path: '/pages/core/mine/authorityManagement/setAuthority', query: {user:user}})
				// uni.navigateTo({
				// 	url:"/pages/core/mine/authorityManagement/setAuthority"
				// })
				// uni.$emit("setAuthority",{
				// 	user:this.searchUser
				// })
			}
		}
	}
</script>

<style lang="less">
	.navbar {
		&__search{
			border-radius: 100rpx;
			display: flex;
			align-items: center;
			
			padding: 0 @uni-spacing-col-lg;
			width: 75%;
			background-color: @uni-bg-color-grey;
			&__text{
				color:#3F536E;
				margin-left: @uni-spacing-row-lg;
			}
		}
		&__submit{
			margin-right: auto;
			margin-left: auto;
		}
	}
.usersearch{
		&__loadding{
			display: flex;
			flex-direction: row;
			justify-content: center;
			margin:@uni-spacing-row-lg 0;
			
		}
		&__result{
			display: flex;
			flex-direction: column;
			&__title{
				margin:@uni-spacing-row-base @uni-spacing-col-lg;
				// font-weight: bolder;
				color: @font-color-grey;
			}
			&__user{
				display: flex;
				align-items: center;
				padding-bottom:10rpx;
				margin:@uni-spacing-row-base @uni-spacing-col-lg;
				border-bottom: 0.5px solid #e2e2e2;
					
				&__pic{
					
				}
				&__text{
					display: flex;
					flex-direction: column;
					
					&__username {
						margin-bottom: 10px;
						font-size: small;
						font-weight: bold;
					}
				
					&__description {
						word-break: break-all;
						text-overflow: ellipsis;
						display: -webkit-box;
						/** 对象作为伸缩盒子模型显示 **/
						-webkit-box-orient: vertical;
						/** 设置或检索伸缩盒对象的子元素的排列方式 **/
						-webkit-line-clamp: 1;
						/** 显示的行数 **/
						overflow: hidden;
						/** 隐藏超出的内容 **/
						font-size: small;
						color: #5e6671;
					}
				
				}
				&__set{
					margin-left: auto ;
					
					display: flex;
					flex-direction: row;
					&__edit{
						margin-right: 10rpx;
						padding: 15rpx 20rpx;
						border-radius: 15rpx;
						background-color: #f5f5f5;
						color: #007AFF;
						font-size: small;
					}
					&__delete{
						
					}
					&__modal{
						display: flex;
						flex-direction: column;
						margin-top: ;
						&__item{
							margin:0px auto 10px 30px;
						}
					}
				}
			}
		}

	
		
	
		

}
</style>
